package com.jzl.canal_consumer.mycat;

import java.util.Random;

/**
 * 租户ID和租户数据库名称缓存
 *
 * @author ZhenWuWang
 */
public class SqlContext
{

    static Random rand = new Random();

    private static ThreadLocal<Long> TENANT_ID = new ThreadLocal<>();

    private static ThreadLocal<String> SCHEMA_NAME = ThreadLocal.withInitial(() -> "");

    public static void setTenantId(Long tenantId)
    {
        TENANT_ID.set(tenantId);
    }

    public static Long getTenantId()
    {
        return TENANT_ID.get();
    }

    public static void setSchemaName(String schemaName)
    {
        SCHEMA_NAME.set(schemaName);
    }

    public static String getSchemaName()
    {
        return SCHEMA_NAME.get();
//      int num=  rand.nextInt(5)+1;
//        return "cloud_ops_depot_"+num;
        // return SCHEMA_NAME.get();
    }

}
